let express = require('express');
let router = express.Router();
let URL = require('url');
let mysql = require('mysql');
let bodyParser = require('body-parser');
let cookieParser = require('cookie-parser');
let session = require('cookie-session');
let mysqlhelp = require("../common/sql");
router.use(bodyParser.urlencoded({extended: true}));
// var User = require('./user'); // get

/**
 * 查询个人信息
 */
router.post('/getInformationData', function (req, res, next) {
    let sql = ''; // 执行的sql
    sql = 'SELECT * FROM personal_information where id = 1';
    mysqlhelp.select(sql).then(function (data) {
        data.isEffective = true;
        res.send(data)
    }).catch(function (err) {
        console.log(err)
    })
});

/**
 * 修改个人信息
 */
router.post('/editInformation', function (req, res, next) {
    let information = req.body;
    let sql = ''; // 执行的sql
    let parameter = [information.name, information.position, information.personalProfile, information.headerImg];
    sql = 'update personal_information set name = ? , position = ? , personalProfile= ? , headerImg= ? where id= 1';
    mysqlhelp.select(sql, parameter).then(function (data) {
        data.isEffective = true;
        res.send(data)
    }).catch(function (err) {
        console.log(err)
    })
});

module.exports = router;
